package br.edu.ufcg.dsc.actions.resource;

import org.apache.struts2.config.Result;
import org.apache.struts2.dispatcher.ServletDispatcherResult;

import br.edu.ufcg.dsc.domain.Resource;
import br.edu.ufcg.dsc.domain.resource.Serial;
import br.edu.ufcg.dsc.services.ResourceService;

import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

@Result(name = "success", type = ServletDispatcherResult.class, value = "/jsp/resource/serial.jsp")
public class FindSerialAction extends ResourceDriven<Serial> implements Preparable, ModelDriven<Serial>{
	
	private int resourceId;
	private Serial serial;
	
	private static final long serialVersionUID = 1L;

	public void prepare() throws Exception {
		Resource resource = ResourceService.find(resourceId);
		if (resource != null)
			serial = new Serial(resource.getMarc());
		else serial = new Serial();
	}

	public int getResourceId() {
		return resourceId;
	}

	public void setResourceId(int resourceId) {
		this.resourceId = resourceId;
	}

	public Serial getSerial() {
		return serial;
	}

	public void setSerial(Serial serial) {
		this.serial = serial;
	}

	public Serial createModel() {
		return serial;
	}

	@Override
	public String execute() {		
		return SUCCESS;
	}

}
